/**
 * file
 */
package com.tdkj.action.front.member.financial;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.tdkj.action.BaseAction;
import com.tdkj.model.exchangerate.BeanExchangeRate;
import com.tdkj.model.financial.BeanExchangeRecord;
import com.tdkj.model.financial.BeanFinancialAccount;
import com.tdkj.service.exchangerate.IBeanExchangeRateService;
import com.tdkj.service.financial.IBeanExchangeRecordService;

/**
 * 
 * FileName: ExchangeIntegralAction.java
 * 
 * @Description: TODO积分兑换
 * 
 *               All rights Reserved, Designed By ZTE-ITS
 * 
 *               Copyright: Copyright(C) 2010-2011
 * 
 *               Company 天成科技有限公司
 * 
 * @author: 李兴建
 * 
 * @version V1.0
 * 
 *          Createdate: 2012-5-27 下午02:16:24
 * 
 * 
 * 
 *          Modification History:
 * 
 *          Date Author Version Discription
 * 
 * 
 *          
 *          ----------------------------------------------------------------------
 *          -------------
 * 
 *          2012-5-27 李兴建 1.0 1.0
 * 
 *          Why & What is modified: <修改原因描述>
 */
public class ExchangeIntegralAction extends BaseAction {
	private static final long serialVersionUID = -3515077824994305313L;
	private BeanFinancialAccount beanAccount;
	private Integer integral;
	private List<BeanExchangeRecord> historyList;
	private BeanExchangeRate exchangeRate;
	private IBeanExchangeRateService exchangeRateService;
	
	private IBeanExchangeRecordService exchangeRecordService;

	@SuppressWarnings("unchecked")
	@Override
	public String execute() throws Exception {
		beanAccount = this.getCurrentUser().getFinancialAccount();
		Criteria criteria = this.createCriteria(BeanExchangeRecord.class);
		criteria.add(Restrictions.eq("user", this.getCurrentUser()));
		criteria.addOrder(Order.desc("dateTime"));
		historyList = criteria.list();
		exchangeRate = exchangeRateService.getExchangeRate();
		return super.execute();
	}

	public String exchange() throws Exception {
		exchangeRecordService.create(this.getCurrentUser().getId(), integral);
		return execute();
	}

	public BeanFinancialAccount getBeanAccount() {
		return beanAccount;
	}

	public void setBeanAccount(BeanFinancialAccount beanAccount) {
		this.beanAccount = beanAccount;
	}

	public List<BeanExchangeRecord> getHistoryList() {
		return historyList;
	}

	public void setHistoryList(List<BeanExchangeRecord> historyList) {
		this.historyList = historyList;
	}

	public BeanExchangeRate getExchangeRate() {
		return exchangeRate;
	}

	public void setExchangeRate(BeanExchangeRate exchangeRate) {
		this.exchangeRate = exchangeRate;
	}

	@Resource
	public void setExchangeRateService(IBeanExchangeRateService exchangeRateService) {
		this.exchangeRateService = exchangeRateService;
	}

	@Resource
	public void setExchangeRecordService(
			IBeanExchangeRecordService exchangeRecordService) {
		this.exchangeRecordService = exchangeRecordService;
	}

	public Integer getIntegral() {
		return integral;
	}

	public void setIntegral(Integer integral) {
		this.integral = integral;
	}

}
